<?php
/**
 * 在职列表
 */
apf_require_controller("Abstract");
apf_require_class("Bll_Report_Report");
apf_require_class("Report_Urls");
class Report_EntryViewController extends AbstractController {

    public function handle_request() {
        $params = $this->request->get_parameters();
        $this->report_bll = new Bll_Report_Report();
        $params['fid'] = empty($params['fid']) ? 0 : intval($params['fid']);

        $this->fun_list = Bll_Hr_Property::get_function_list();
        $bu_list = Bll_Hr_Property::get_business_list();
        $data['datalist'] = $this->_get_list($params);

        $title = empty($params['fid']) ? '' : $this->fun_list[$params['fid']]['function_name'];
        //tp($data['datalist']);
        $this->request->set_attribute('params', $params);
        $this->request->set_attribute('fun_list', $this->fun_list);
        $this->request->set_attribute('bu_list', $bu_list);
        $this->request->set_attribute('title',$title );
        $this->request->set_attribute('data', $data);
        return "Report_EntryView";
    }

    private function _get_list($params){
        $_where = array();
        if(!empty($params['fid'])){
            $_where['function_id'] = $params['fid'];
            //根据职能取所有的事业部
            $hroa_bll = new Bll_Hr_OutInterface();
            $filldata=$hroa_bll->get_bu_by_function($params['fid']);
        }else{
            $filldata = $this->fun_list;
        }
        //数据模板
        $tpl = $this->report_bll->on_job_tpl();
        $data = $this->report_bll->search_on_job_list($_where);
        $datalist[999] = $data[999];
        //再取出有部门规划,但还没有人的部部门
        $plan_data=$this->report_bll->get_current_on_job($this->user_info['user_id']);
        if(!empty($params['fid'])){//根据职能单取

        }else{
            $datalist[999]['plan_num'] = $plan_data['plan_num'];
        }
        foreach($filldata as $fid=>$val){
            if(empty($data[$fid])){
                //$datalist[$fid] =$tpl;
            }else{
                $datalist[$fid] =$data[$fid];
            }
        }
        return $datalist;
    }
}